//
//  GoodsSearchView.m
//  WeiYiMei
//
//  Created by iMac on 2019/4/23.
//  Copyright © 2019年 liyefu. All rights reserved.
//

#import "GoodsSearchView.h"
#import "LLSearchBar.h"

@interface GoodsSearchView ()<UISearchBarDelegate>

@property (nonatomic, strong) LLSearchBar *searchBar;
@property (nonatomic, strong) UIButton *searchBtn;

@end

@implementation GoodsSearchView

- (void)setupSubViews
{
    self.searchBar = [[LLSearchBar alloc] init];
    self.searchBar.textFieldContentInset = UIEdgeInsetsMake(5, 0, 5, 0);
    self.searchBar.backgroundImage = [UIImage new];
    self.searchBar.searchFieldColor = kColorF2F2F2;
    self.searchBar.semicircle = YES;
    self.searchBar.placeholder = @"请输入关键词搜索";
    self.searchBar.placeholderTextColor = kColor999999;
    self.searchBar.font = [UIFont systemFontOfSize:13];
    self.searchBar.delegate = self;
    [self addSubview:self.searchBar];
    
    self.searchBtn = [[UIButton alloc] init];
    [self.searchBtn setTitle:@"搜索" forState:UIControlStateNormal];
    self.searchBtn.titleLabel.font = [UIFont systemFontOfSize:13];
    [self.searchBtn setTitleColor:kColor666666 forState:UIControlStateNormal];
    [self addSubview:self.searchBtn];
    [self.searchBtn addTarget:self action:@selector(searchAcion:) forControlEvents:UIControlEventTouchUpInside];
}

- (void)setupConstraints
{
    [self.searchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.top.bottom.equalTo(self);
        make.right.equalTo(self).offset(-16);
    }];
    
    [self.searchBar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.left.equalTo(self).offset(16);
        make.top.bottom.equalTo(self);
        make.right.equalTo(self.searchBtn.mas_left).offset(-10);
    }];
}

- (void)searchAcion:(id)sender
{
    if (self.searchHandler) {
        self.searchHandler(self.searchBar.text);
    }
}

@end
